﻿using MiniFox.Utility;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;

namespace DMC.Core.Models
{
    public class CommandParameter
    {
        [Key]
        [Display(Name = "参数名称", ShortName = "名称")]
        [Required(ErrorMessage = "参数名称[name]必须填写")]
        [JsonProperty("name")]
        [Column("name")]
        public string Name { get; set; }

        [Display(Name = "参数名", ShortName = "参数名")]
        [Required(ErrorMessage = "参数名[parameterName]必须填写")]
        [JsonProperty("parameterName")]
        [Column("parameterName")]
        public string ParameterName { get; set; }

        [Display(Name = "类型", ShortName = "类型")]
        [Required(ErrorMessage = "请填写参数类型")]
        [JsonProperty("type")]
        [Column("type")]
        public string CLRTypeName { get; set; }
        [JsonIgnore]
        public Type CLRType
        {
            get
            {
                var type = Type.GetType(CLRTypeName);
                return type;
            }
        }

        [Display(Name = "可空", ShortName = "可空")]
        [JsonProperty("nullable")]
        [Column("nullable")]
        public bool Nullable { get; set; }

        [Display(Name = "默认值", ShortName = "默认值")]
        [JsonProperty("defaultValue")]
        [Column("defaultValue")]
        public string? DefaultValue { get; set; }

        [Display(Name = "传参方式", ShortName = "传参方式")]
        [Required(ErrorMessage = "请选择一个传参方式")]
        [JsonProperty("direction")]
        [Column("direction")]
        public ParameterDirection Direction { get; set; }

        [Display(Name = "精度", ShortName = "精度")]
        [JsonProperty("precision")]
        [Column("precision")]
        public byte Precision { get; set; }

        [Display(Name = "小数位", ShortName = "小数位")]
        [JsonProperty("scale")]
        [Column("scale")]
        public byte Scale { get; set; }

        [Display(Name = "范围", ShortName = "范围")]
        [JsonProperty("size")]
        [Column("size")]
        public int Size { get; set; }

        [Display(Name = "参数描述", ShortName = "参数描述"), MaxLength(100)]
        [JsonProperty("description")]
        [Column("description")]
        public string? Description { get; set; }
    }
}
